import request from '@/utils/request'
import type { Word, ApiResponse } from '@/types'

export const vocabularyApi = {
  // 获取单词列表
  getVocabulary(params?: any): Promise<ApiResponse<{ words: Word[]; pagination: any }>> {
    return request.get('/vocabulary', { params })
  },
  
  // 获取单词详情
  getWordDetail(wordId: number): Promise<ApiResponse<Word>> {
    return request.get(`/vocabulary/${wordId}`)
  },
  
  // 获取待学习的单词
  getWordsToLearn(limit?: number): Promise<ApiResponse<Word[]>> {
    return request.get('/vocabulary/learn', { params: { limit } })
  },
  
  // 获取待复习单词
  getReviewWords(limit?: number): Promise<ApiResponse<Word[]>> {
    return request.get('/vocabulary/review', { params: { limit } })
  },
  
  // 获取薄弱单词
  getWeakWords(limit?: number): Promise<ApiResponse<Word[]>> {
    return request.get('/vocabulary/weak', { params: { limit } })
  },
  
  // 记录学习进度
  recordProgress(wordId: number, correct: boolean): Promise<ApiResponse> {
    return request.post('/vocabulary/progress', { word_id: wordId, correct })
  },
  
  // 记录答题结果
  recordAnswer(data: { wordId: number; isCorrect: boolean }): Promise<ApiResponse> {
    return request.post('/vocabulary/answer', data)
  },
  
  // 获取统计信息
  getStatistics(): Promise<ApiResponse> {
    return request.get('/vocabulary/statistics')
  }
}

